package com.lc.controller;

import com.cnpc.framework.base.entity.BaseResponse;
import com.lc.entity.LogRecord;
import com.lc.service.LogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by 下雨不带伞 on 2020/3/20.
 */
@RequestMapping("log")
@Controller
public class LogController {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    LogService logService;


    @ResponseBody
    @RequestMapping("addLogRecord")
    public BaseResponse addLogRecord(@RequestBody LogRecord logRecord) {
        BaseResponse response = null;
        try {
            response = logService.addLogRecord(logRecord);

        } catch (Exception ex) {
            logger.error(ex.getMessage());
            ex.printStackTrace();
            response = new BaseResponse();
            response.setStatus(1);
            response.setMessage("系统繁忙");
        }
        return response;
    }

    @ResponseBody
    @RequestMapping("getLogRecordList")
    public BaseResponse getLogRecordList(@RequestParam("token") String token,
                                         @RequestParam(value = "logType", required = false) String logType,
                                         @RequestParam(value = "infoid", required = false) String infoid,
                                         @RequestParam(value = "startTime", required = false) String startTime,
                                         @RequestParam(value = "endTime", required = false) String endTime,
                                         @RequestParam(value = "content", required = false) String content,
                                         @RequestParam(value = "type", required = false) String type,
                                         @RequestParam(value = "pageNum", required = false) Integer pageNum,
                                         @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        BaseResponse response = null;
        try {
            response = logService.getLogRecordList(token,logType, infoid, startTime, endTime, content, type, pageNum, pageSize);

        } catch (Exception ex) {
            logger.error(ex.getMessage());
            ex.printStackTrace();
            response = new BaseResponse();
            response.setStatus(1);
            response.setMessage("系统繁忙");
        }
        return response;
    }

    @ResponseBody
    @RequestMapping("getLogRecord")
    public BaseResponse getLogRecord(@RequestParam("id") String id) {
        BaseResponse response = null;
        try {
            response = logService.getLogRecord(id);

        } catch (Exception ex) {
            logger.error(ex.getMessage());
            ex.printStackTrace();
            response = new BaseResponse();
            response.setStatus(1);
            response.setMessage("系统繁忙");
        }
        return response;
    }

    @ResponseBody
    @RequestMapping("deleteLogRecord")
    public BaseResponse deleteLogRecord(@RequestParam("id") String id) {
        BaseResponse response = null;
        try {
            response = logService.deleteLogRecord(id);

        } catch (Exception ex) {
            logger.error(ex.getMessage());
            ex.printStackTrace();
            response = new BaseResponse();
            response.setStatus(1);
            response.setMessage("系统繁忙");
        }
        return response;
    }

}
